package com.szholly.plug.safe.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.szholly.plug.safe.entity.user.UserEntity;

/**
 * 定义用户信息
 */
public class CustomUserDetails implements UserDetails {

	private static final long serialVersionUID = 2869691769870829660L;

	private UserEntity userEntity;
	private Collection<GrantedAuthority> roles;

	public CustomUserDetails(UserEntity userEntity,
			Collection<GrantedAuthority> roles) {
		this.userEntity = userEntity;
		this.roles = roles;
	}

	public UserEntity getUserEntity() {
		return userEntity;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return roles;
	}

	@Override
	public String getPassword() {
		return userEntity.getPassword();
	}

	@Override
	public String getUsername() {
		return userEntity.getUserName();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}
}
